// pages/mch/order/detail.js
const App = getApp()
import Kits from '../../../utils/kits'
import Util from '../../../utils/util'

Page({
  data: {
    init: false,
    debug: App.Global.Debug,

    order: {},

    showInfo: false,
    postInfo: false,
    getInfo: false,

    unbill: {},
    changep: false,
    total: '',
    maxTotal: '',
    bid: '',

    biz: '',
    qrpay: false,
    qr: '',
    pamt: '',
    pcnl: '',
    pid: '',


    change: false,
    cstep: 1,
    selDate: '',
    changePamt: '',
    // minDate: undefined,
    curDate: undefined,
    filter(type, options) {
      if (type === 'minute') {
        return options.filter((option) => option % 30 === 0);
      }
      return options;
    },

    timer: undefined,

    forfeit: '',
    forfeitFromDeposit: "",
    Points: '',
    forfeit_from_deposit_type: 1,
    forfeit_from_deposit_memo: '',
    violation_time: '',
    location: '',

    add: false,
    forfeits: [],

    timeShow: false,
    maxDate: new Date().getTime(),
    minDate: '',
    hcMaxDate: "",
    showOrderInfo: false,
    showOrderPhoneInfo: false,
    showTimeLine: false,
    showMoreSources:{
      delivery:false,
      restore:false,
    },
    billchangep: false,
    unbills: [],
    statenum:null,
    oidd:{}
  },
  getInfoMet() {
    this.setData({
      getInfo: !this.data.getInfo
    })
  },
  postInfoMet() {
    this.setData({
      postInfo: !this.data.postInfo
    })
  },
  showInfoMet() {
    this.setData({
      showInfo: !this.data.showInfo
    })
  },
  showInfoOrderMet() {
    this.setData({
      showOrderInfo: !this.data.showOrderInfo
    })
  },
  showInfoOrderPhoneMet() {
    this.setData({
      showOrderPhoneInfo: !this.data.showOrderPhoneInfo
    })
  },
  showTimeLineMet() {
    this.setData({
      showTimeLine: !this.data.showTimeLine
    })
  },
  showMSPriceToast() {
    wx.showToast({
      title: '免收金额表示未经过本平台收取的金额',
      icon: 'none',
      duration: 2000
    })
  },
  getToPhone() {
    wx.makePhoneCall({
      phoneNumber: this.data.order.customer.phone
    })
  },
  getToCustomer(){
    wx.navigateTo({
      url: '/pages/mch/member/detail?mid=' + this.data.order.customer.id
    })
  },
  onLoad(options) {
    console.log(options,"初始数据")
    // this.execLoad(options.oid)
    // this.load(options.oid)
    this.setData({
      oidd:options
    })
    App.doPost({
      uri: '/app/merchant/order/detail',
      body: {
        id:options.oid //oid
      },
      fnSucc: resp => {

        resp.data.deposit.totalStr = Kits.fmtMoneyString(resp.data.deposit.total)
        resp.data.deposit.fineStr = Kits.fmtMoneyString(resp.data.deposit.fine)
        resp.data.deposit.refundStr = Kits.fmtMoneyString(resp.data.deposit.refund)
        resp.data.deposit.vosStr = Kits.fmtMoneyString(resp.data.deposit.total - resp.data.deposit.refund)

        resp.data.rent.totalStr = Kits.fmtMoneyString(resp.data.rent.total)
        resp.data.rent.paidStr = Kits.fmtMoneyString(resp.data.rent.paid)
        resp.data.rent.dayStr = Kits.fmtMoneyString(resp.data.rent.day)
        resp.data.rent.carStr = Kits.fmtMoneyString(resp.data.rent.car)
        resp.data.rent.adjustStr = Kits.fmtMoneyString(resp.data.rent.adjust)
        resp.data.rent.couponStr = Kits.fmtMoneyString(resp.data.rent.coupon)
        resp.data.rent.realStr = Kits.fmtMoneyString(resp.data.rent.real)
        resp.data.rent.pamtStr = Kits.fmtMoneyString(resp.data.rent.real - resp.data.rent.paid)

        this.data.unbill = {}
        const unbills = []
        resp.data.bills.forEach(bill => {
          if(bill.createTime){
            bill.createTime = this.formatCurrentYearTime(bill.createTime)
          }
          if(bill.finishTime){
            if(bill.finishTime === '0001-01-01T00:00:00Z'){
              bill.finishTime = ''
            }else{
              bill.finishTime = this.formatCurrentYearTime(bill.finishTime)
            }
          }
          if(bill.name === '违章罚款代缴'){
            bill.isHideMSBtn = true
          }
          if(bill.paymentChannel){
            bill.payType = this.getPayType(bill.paymentChannel)
          }
          if(bill.begin){
            bill.begin = this.formatCurrentYearTime(bill.begin)
          }
          if(bill.close){
            bill.close = this.formatCurrentYearTime(bill.close)
          }
          if(!bill.paid){
            unbills.push(bill)
          }
          if (!bill.paid && !this.data.unbill.id) {
            this.setData({
              unbill: bill
            })
          } else {
            this.setData({
              unbill: {}
            })
          }
        })
        this.setData({
          unbills: [...unbills]
        })
        console.log('unbills', this.data.unbills)
        let sources = []
        if(Array.isArray(resp.data.delivery.photo)){
          resp.data.delivery.photo.forEach(p => {
            sources[sources.length] = {
              url: p,
              type: 'image'
            }
          })
        }
        if(Array.isArray(resp.data.delivery.detail)){
          resp.data.delivery.detail.forEach(p => {
            sources[sources.length] = {
              url: p,
              type: 'image'
            }
          })
        }
        if(Array.isArray(resp.data.delivery.video)){
          resp.data.delivery.video.forEach(p => {
            sources[sources.length] = {
              url: p,
              type: 'video'
            }
          })
        }
        resp.data.delivery.sources = sources

        let sourcesrestore = []
        if(Array.isArray(resp.data.restore.photo)){
          resp.data.restore.photo.forEach(p => {
            sourcesrestore[sourcesrestore.length] = {
              url: p,
              type: 'image'
            }
          })
        }
        if(Array.isArray(resp.data.restore.detail)){
          resp.data.restore.detail.forEach(p => {
            sourcesrestore[sourcesrestore.length] = {
              url: p,
              type: 'image'
            }
          })
        }
        if(Array.isArray(resp.data.restore.video)){
          resp.data.restore.video.forEach(p => {
            sourcesrestore[sourcesrestore.length] = {
              url: p,
              type: 'video'
            }
          })
        }
        resp.data.restore.sources = sourcesrestore
        const newBills = []
        if(resp.data.bills && Array.isArray(resp.data.bills)){
          resp.data.bills.forEach(bill=>{
            const findNewBillIndex = newBills.findIndex(nBill=>nBill.type === bill.type)
            if(findNewBillIndex > -1){
              const billItem = newBills[findNewBillIndex]
              if(billItem.begin && billItem.close){
                billItem.begin = billItem.begin > bill.begin ? bill.begin : billItem.begin
                billItem.close = billItem.close < bill.close ? bill.close : billItem.close
              }
              newBills[findNewBillIndex].amount = Number(billItem.amount) + Number(bill.amount)
              if(bill.originalAmount){
                newBills[findNewBillIndex].originalAmounttotal = Number(newBills[findNewBillIndex].originalAmounttotal || 0) + Number(bill.originalAmount / 100)
              }else{
                newBills[findNewBillIndex].originalAmounttotal = Number(newBills[findNewBillIndex].originalAmounttotal) + Number(bill.origin_amount)
              }
            }else{
              newBills.push({
                ...bill,
                originalAmounttotal: 
                bill.originalAmount ? Number(bill.originalAmount / 100) : Number(bill.amount)
              })
            }
          })
        }
        newBills.forEach(item=>{
          if(item.begin && item.close){
            // 计算出天数
            const begin = new Date(item.begin)
            const close = new Date(item.close)
            const days = (close.getTime() - begin.getTime()) / (1000 * 60 * 60 * 24)
            item.days = Math.ceil(days)
            // 平均每天的金额
            item.avgPrice = (item.amount / item.days).toFixed(2)
          }
        })

        // 扣除增值服务 ----------
        if(resp.data.service && Array.isArray(resp.data.service)){
          const serviceTotal = resp.data.service.reduce((sum, service) => {
            return sum + (Number(service.total) || 0)
          }, 0)
          
          newBills.forEach(bill => {
            // 默认从第一个账单扣除全部服务费（根据业务需求调整）
            if(bill.type === 1){ // 假设type=1是主账单
              bill.amount = Math.max(0, Number(bill.amount) - serviceTotal)
              // 同步调整原价（如果有折扣）
              if(bill.originalAmounttotal){
                bill.originalAmounttotal = Math.max(0, bill.originalAmounttotal - serviceTotal)
                bill.origin_amount = Math.max(0, bill.origin_amount - serviceTotal)
              }
            }
          })
          newBills.forEach(item=>{
            if(item.begin && item.close){
              // 计算出天数
              const begin = new Date(item.begin)
              const close = new Date(item.close)
              const days = (close.getTime() - begin.getTime()) / (1000 * 60 * 60 * 24)
              item.days = Math.ceil(days)
              // 平均每天的金额
              item.avgPrice = (item.amount / item.days).toFixed(2)
            }
          })
        }

        resp.data.newBills = newBills
        console.log('newBills', resp.data.bills,newBills)

        const formatTimes = ()=>{
          // 时间轴
          const timelines = []
          if(resp.data.times){
            if(resp.data.times.paid){
              timelines.push({
                time: resp.data.times.paid,
                timeStr: this.formatCurrentYearTimeSencord(resp.data.times.paid),
                title: '付款时间'
              })
            }
            if(resp.data.times.delivery){
              timelines.push({
                time: resp.data.times.delivery,
                timeStr: this.formatCurrentYearTimeSencord(resp.data.times.delivery),
                title: '交车时间'
              })
            }
          }
          if(resp.data.deposit.part){
            timelines.push({
              time: resp.data.deposit.part,
              timeStr: this.formatCurrentYearTimeSencord(resp.data.deposit.part),
              title: '车辆押金退款'
            })
          }
          if(resp.data.deposit.full){
            timelines.push({
              time: resp.data.deposit.full,
              timeStr: this.formatCurrentYearTimeSencord(resp.data.deposit.full),
              title: '违章押金退款'
            })
          }
          if(resp.data.times.create){
            resp.data.times.createStr = this.formatCurrentYearTimeSencord(resp.data.times.create)
          }
          if(resp.data.delivery.time){
            resp.data.delivery.timeStr = this.formatCurrentYearTimeSencord(resp.data.delivery.time)
          }
          if(resp.data.restore.time){
            resp.data.restore.timeStr = this.formatCurrentYearTimeSencord(resp.data.restore.time)
          }
          // 按时间排序
          timelines.sort((a,b)=>{
            return new Date(a.time).getTime() - new Date(b.time).getTime() > 0 ? -1 : 1
          })
          resp.data.timelines = timelines

          resp.data.beginStr = this.formatCurrentYearTime(resp.data.begin)
          resp.data.closeStr = this.formatCurrentYearTime(resp.data.close)
        }
        formatTimes()
        this.setData({
          init: true,
          order: resp.data,
          minDate: new Date(resp.data.begin + ':00').getTime(),
          maxDate: new Date(resp.data.close + ':00').getTime()
        })
        this.data.order.newBills.forEach(item=>{
          if(typeof item.amount == 'string'){
            item.amount=parseInt(item.amount)
          }
          if(typeof item.origin_amount == 'string'){
            item.origin_amount=parseInt(item.origin_amount)
          }
        })
        this.setData({
          'order.newBills':this.data.order.newBills
        })
        this.load(options.oid)
      }
    })
  },
  load(id) {
    App.doPost({
      // /app/order/violation/list
      uri: '/app/merchant/violation/list',  // 获取违章信息
      body: {
        order_id: Number(id)
      },
      fnSucc: resp => {
        console.log(resp.data.items);
        const forfeits = resp.data.items
        if(Array.isArray(forfeits) && forfeits.length > 0) {
          forfeits.forEach(item => {
            item.DTime = this.formatTimestampMitute(item.Time)
            item.DTimeStr = this.formatCurrentYearTime(item.Time)
          })
        }
        if(forfeits.length > 0 && this.data.order.bills) {
          const billsF = this.data.order.bills.filter(bill => !bill.paid)
          billsF.forEach((bill,index) => {
            if(forfeits[index]){
              forfeits[index].remark = bill.memo
            }
          })
        }
        console.log('forfeits', forfeits)
        this.setData({
          forfeits: forfeits
        })
      }
    })
  },
  addData() {
    this.setData({
      add: !this.data.add
    })
  },
  formatTimestamp(timestamp) {
    const date = new Date(timestamp);
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0');
    const day = String(date.getDate()).padStart(2, '0');
    const hours = String(date.getHours()).padStart(2, '0');
    const minutes = String(date.getMinutes()).padStart(2, '0');
    const seconds = String(date.getSeconds()).padStart(2, '0');

    return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  },
  formatTimestampMitute(timestamp) {
    const date = new Date(timestamp);
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0');
    const day = String(date.getDate()).padStart(2, '0');
    const hours = String(date.getHours()).padStart(2, '0');
    const minutes = String(date.getMinutes()).padStart(2, '0');
    return `${year}-${month}-${day} ${hours}:${minutes}`;
  },
  onInput(e) {
    console.log(e);
    const date = this.formatTimestamp(e.detail)
    this.setData({
      violation_time: date,
      timeShow: false
    })
    
  },
  onCloseTime() {
    this.setData({
      timeShow: !this.data.timeShow
    })
    console.log(this.data.minDate,this.data.maxDate,"最大最小时间")
  },
  saveViolation() {
    if (this.data.Points % 3 !== 0 && this.data.Points != 1) {
      Util.Notify.warn(`请填写正确的违章扣分`)
      return
    }

    if (this.data.reason == '') {
      Util.Notify.warn(`请填写违章备注`)
      return
    }

    if (this.data.location == '') {
      Util.Notify.warn(`请填写违章地点`)
      return
    }

    if (this.data.violation_time == '') {
      Util.Notify.warn(`请选择违章时间`)
      return
    }
    const data = {
      order_id: Number(this.data.order.id),
      car_id: Number(this.data.order.car.id),
      reason: this.data.forfeit_from_deposit_memo,
      Points: this.data.Points * 1,
      forfeit: this.data.forfeit * 100,
      forfeit_from_deposit: this.data.forfeitFromDeposit * 100,
      violation_time: this.data.violation_time,
      location: this.data.location
    }

    console.log('save', data)
    App.doPost({
      uri: '/app/merchant/violation/save',
      body: data,
      fnSucc: resp => {
        this.addData()
        this.load(this.data.order.id)
        this.onLoad(this.data.oidd)
      }
    })
  },
  onUnload() {
    if (this.data.timer) {
      clearTimeout(this.data.timer)
    }
  },
  closeModal() {
    this.setData({
      qrpay: false
    })
  },
  // execLoad(oid) {
    
  // },
  getPayType(type){
    switch(type){
      case 10:
        return '钱包支付'
      case 20:
        return '微信扫码'
      case 21:
        return '微信小程序支付'
      case 22:
        return '微信APP支付'
      case 23:
        return '微信信用分'
      case 30:
        return '支付宝扫码'
      case 31:
        return '支付宝小程序'
      case 32:
        return '支付宝APP支付'
      case 33:
        return '支付宝预授权支付'
      case 40:
        return '跳过支付'
      default:
        return ''
    }
  },
  toDelivery() {
    wx.redirectTo({
      url: "/pages/mch/order/delivery?oid=" + this.data.order.id
    })
  },
  toRestore() {
    wx.redirectTo({
      url: "/pages/mch/order/restore?oid=" + this.data.order.id
    })
  },
  toSign() {
    wx.redirectTo({
      url: "/pages/mch/order/sign?oid=" + this.data.order.id
    })
  },

  doShowTimeChange() {
    let btime = Kits.parseDatetime(this.data.order.close + ":00").getTime()
    let ntime = new Date().getTime()
    this.setData({
      minDate: Kits.getNextTime(btime > ntime ? btime : ntime).getTime(),
      curDate: Kits.parseDatetime(this.data.order.close + ":00").getTime() + 48 * 60 * 60 * 1000,
      cstep: 1,
      change: true,
      hcMaxDate: Kits.parseDatetime(this.data.order.close + ":00").getTime() + 180 * 24 * 60 * 60 * 1000,
    })
  },
  doShowBillChange(e) {
    let statenum = e.currentTarget.dataset.statenum
    this.setData({
      billchangep: true,
      statenum:statenum
    })
  },
  doHideBillChange() {
    this.setData({
      billchangep: false
    })
  },
  doHideTimeChange() {
    this.setData({
      change: false
    })
  },
  doNextTimeChange(e) {
    let ctime = new Date(e.detail).format('yyyy-MM-dd HH:mm')

    App.doPost({
      uri: '/app/merchant/order/time/change',
      body: {
        id: this.data.order.id,
        close: ctime + ":00",
        ask: true
      },
      fnSucc: resp => {
        this.setData({
          cstep: 2,
          selDate: ctime,
          changePamt: Kits.fmtMoneyString(resp.data.pamt)
        })
      },

    })
  },
//  修改换车时间
  doSubmitTimeChange() {

    App.doPost({
      uri: '/app/merchant/order/time/change',
      body: {
        id: this.data.order.id,
        close: this.data.selDate + ":00",
        ask: false
      },
      fnSucc: (resp) => {
        this.setData({
          change: false
        })
       
        if (resp.data.pamt > 0) {
          Util.Toast.succ(`变更成功，客户还需支付${Kits.fmtMoneyString(resp.data.pamt)}元`)
        } else {
          Util.Toast.succ(`变更成功`)
        }
        this.onLoad(this.data.oidd)

      }

    })
  },
// 打开调价
  showChange(e) {
    if(this.data.order.state === 9){
      Util.Notify.warn(`订单已取消，无法调整账单`)
      return
    }
    const bidItem = this.data.order.bills.find(bill=> bill.id === e.currentTarget.dataset.bid) || {}
    console.log('bidItem', bidItem)
    this.setData({
      changep: true,
      bid: e.currentTarget.dataset.bid,
      total: bidItem.amount || "",
      maxTotal: bidItem.amount
    })
  },
  // 调价取消
  hideChange() {
    this.setData({
      changep: false,
      total: 0
    })
  },
  doPreviewItem(e) {
    let type = e.currentTarget.dataset.type
    let cata = e.currentTarget.dataset.cata
    console.log(cata)
    let sources = []
    console.log(this.data.order[cata][type])
    this.data.order[cata][type].forEach(p => {
      sources[sources.length] = {
        url: p,
        type: type == 'video' ? 'video' : 'image'
      }
    })

    let current = this.data.order[cata][type].findIndex(p => p == e.currentTarget.dataset.url)
    console.log(sources, current)
    wx.previewMedia({
      sources: sources,
      current: current
    })
  },
  doPreviewItem2(e) {
    let index = e.currentTarget.dataset.index

    let cata = e.currentTarget.dataset.cata
    let sources = this.data.order[cata].sources
    console.log(sources)
    let current = index

    wx.previewMedia({
      sources: sources,
      current: current
    })
  },
  showMoreSources(e){
    let type = e.currentTarget.dataset.type
    this.setData({
      showMoreSources:{
        [type]:!this.data.showMoreSources[type]
      }
    })
  },
  // 调价修改
  doSaveChnagePrice() {
    if (parseInt(this.data.total) < 0) {
      Util.Notify.warn(`请填写有效的账单金额`)
      return
    }

    if(Number(this.data.total) > Number(this.data.maxTotal)){
      Util.Notify.warn(`修改后的金额不能大于 ` + this.data.maxTotal)
      return
    }
    
    App.doPost({
      uri: '/app/merchant/order/price/change',
      body: {
        id: this.data.order.id,
        bid: this.data.bid,
        total: parseInt(this.data.total) * 100
      },
      fnSucc: () => {
        Util.Toast.succ(`修改成功`)
        this.setData({
          changep: false
        })
        setTimeout(()=>{
          console.log(this.data.change,"successMes")
        },200)
        this.onLoad(this.data.oidd)
      }
    })
  },
  // 删除
  doDeleteSaveChnagePrice(e) {
    if(this.data.order.state === 9){
      Util.Notify.warn(`订单已取消，无法删除账单`)
      return
    }
    wx.showModal({
      title: '删除提示',
      cancelText: '点错了',
      confirmText: '确认删除',
      confirmColor: '#e54d42',
      content: '是否删除该账单？',
      success: (res) => {
        if (res.confirm) {
          App.doPost({
            uri: '/app/merchant/bill/delete',
            body: {
              id: this.data.order.id,
              bid: e.currentTarget.dataset.bid,
              // total: 0
            },
            fnSucc: () => {
              Util.Toast.succ(`删除成功`)
              // this.onLoad(this.data.oidd)
              this.setData({
                changep: false,
              })
              this.onLoad(this.data.oidd)
            }
          })
        }
      }
    })

  },
  doChange() {
    Util.Notify.warn(`暂不可调整租期`)

  },
  doCancel() {
    wx.showModal({
      title: '取消提示',
      cancelText: '点错了',
      confirmText: '确认取消',
      confirmColor: '#e54d42',
      content: '是否取消订单？',
      success: (res) => {
        if (res.confirm) {
          App.doPost({
            uri: '/app/merchant/order/cancel',
            body: {
              id: this.data.order.id,
              memo: '门店取消订单'
            },
            fnSucc: () => {
              wx.pub("ReloadOrderList", {})
              this.onLoad(this.data.oidd)
            }
          })
        }
      }
    })
  },
  // 免收
  doFreeCharge(e) {
    console.log(e.currentTarget,"biddd")
    if(this.data.order.state === 9){
      Util.Notify.warn(`订单已取消，无法免收账单`)
      return 
    }
    wx.showModal({
      title: '确认免收提示',
      cancelText: '点错了',
      confirmText: '确认',
      confirmColor: '#e54d42',
      content: '是否免收该账单？',
      success: (res) => {
        if (res.confirm) {
          App.doPost({
            uri: '/app/merchant/order/pay/skip_bill',
            body: {
              bill_id: e.currentTarget.dataset.bid,
            },
            fnSucc: () => {
              Util.Toast.succ(`免收成功`)
              this.onLoad(this.data.oidd)
            }
          })
        }
      }
    })

  },
  showPayqr(e) {
    this.setData({
      biz: e.currentTarget.dataset.biz,
      qrpay: true,
    })
  },
  doPayment(e) {
    if (this.data.loading) {
      return
    }
    this.setData({
      loading: true
    })
    let type = e.currentTarget.dataset.type
    this.setData({
      qr: ''
    })
    App.doPost({
      uri: '/app/merchant/order/pay/qr',
      body: {
        type: this.data.biz,
        data: this.data.order.id,
        pcnl: parseInt(type),
        parg: JSON.stringify({
          appid: App.Global.AppId,
          puser: App.Global.OpenId,
        })
      },
      fnSucc: (resp) => {
        let url = type == '20' ? resp.data.wxqr.url : resp.data.aliqr.url
        this.setData({
          pid: resp.data.id,
          qr: url,
          pamt: Kits.fmtMoneyString(resp.data.amount),
          pcnl: type == '20' ? '微信' : '支付宝'
        })
        this.execCheckPay()
      },
      fnFail: resp => {
        Util.Notify.error(`[${resp.stat.err}] ${resp.stat.msg}`)
      },
      fnComp: () => {
        this.setData({
          loading: false
        })
      }
    })

  },
  execCheckPay() {
    App.doPost({
      uri: '/app/base/payment/state',
      body: {
        id: this.data.pid,
      },
      fnSucc: resp => {
        if (resp.data.state == 1) {
          if (this.data.timer) {
            clearTimeout(this.data.timer)
          }
          this.data.timer = setTimeout(() => {
            this.execCheckPay()
          }, 1000)

          return
        }
        Util.Toast.clear()
        if (resp.data.state == 2) {
          Util.Toast.succ('用户已支付')
          this.setData({
            qrpay: false
          })
          this.onLoad(this.data.oidd)
        }
      },
    })
  },
  // 押金跳过支付
  doSkip() {
    const _this = this
    let RentId, DepositId
    wx.showModal({
      title: '确认跳过支付',
      cancelColor: 'cancelColor',
      success: (res) => {
        if(res.confirm){
          let biz = 'Deposit'
          App.doPost({
            uri: '/app/merchant/order/pay/qr',
            body: {
              type: biz,
              data: this.data.order.id,
              pcnl: parseInt(20),
              parg: JSON.stringify({
                appid: App.Global.AppId,
                puser: App.Global.OpenId,
              })
            },
            fnSucc: (resp) => {
              DepositId = resp.data.id
              
              App.doPost({
                uri: '/app/merchant/order/pay/skip',
                body: {
                  deposit_payment_id: DepositId,
                  // rent_payment_id: RentId
                },
                fnSucc: (resp) => {
                  _this.execLoad(_this.data.order.id)
                  this.onLoad(this.data.oidd)
                }
              })
              this.onLoad(this.data.oidd)
            }
          })
        }
      }
    })
  },
  execTestPay() {
    if (!this.data.debug) {
      return
    }
    if (this.data.loading) {
      return
    }
    this.setData({
      loading: true
    })

    App.doPost({
      uri: '/dev/op/payment/finish',
      body: {
        pid: this.data.pid,
      },
      fnSucc: resp => {
        console.log(resp.data)
      },
      fnFail: resp => {
        Util.Notify.error(`[${resp.stat.err}] ${resp.stat.msg}`)
      },
      fnComp: () => {
        this.setData({
          loading: false
        })
      }
    })
  },
  formatCurrentYearTime (time) {
    const date = new Date(time)
    const now = new Date()
    if (date.getFullYear() === now.getFullYear()) {
      return date.format('MM-dd HH:mm')
    } else {
      return date.format('yyyy-MM-dd HH:mm')
    }
  },
  formatCurrentYearTimeSencord (time) {
    const date = new Date(time)
    const now = new Date()
    if (date.getFullYear() === now.getFullYear()) {
      return date.format('MM-dd HH:mm:ss')
    } else {
      return date.format('yyyy-MM-dd HH:mm:ss')
    }
  },
  conslo(){
    console.log(this.data.order.newBills,"scio8")
  }
})